package com.dev.op.util;

import org.springframework.stereotype.Component;

@Component
public class OutputComparator {
    /**
     * 标准对比方式：忽略尾部换行符和空格
     */
    public boolean isOutputCorrect(String actualOutput, String expectedOutput) {
        if (actualOutput == null || expectedOutput == null) return false;

        return normalize(actualOutput).equals(normalize(expectedOutput));
    }

    /**
     * 标准化输出：去掉首尾空格和多余换行
     */
    private static String normalize(String output) {
        return output.trim().replaceAll("[\\s\\u0000]+$", ""); // 去掉末尾所有空格/换行/null字符
    }
}
